//
//  ProvinceCCInfo.m
//  HuiYun
//
//  Created by 刘锦锋 on 16/8/14.
//  Copyright © 2016年 hpx. All rights reserved.
//

#import "ProvinceCCInfo.h"

@implementation ProvinceCCInfo

+ (ProvinceCCInfo *)shareManager
{
    static ProvinceCCInfo *handler = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        handler = [[ProvinceCCInfo alloc] init];
    });
    return handler;
}

- (instancetype)init
{
    self = [super init];
    if (self)
    {
        [self getProvinceData];
    }
    return self;
}

#pragma mark -
- (void)getProvinceData
{
//    [[LJFNetworkingManager shareManager] POST:PROVINCECITYCURL parameters:nil success:^(id returnData, int code, NSString *msg)
//     {
//         if (code == 200)
//         {
//             NSLog(@"msg == %@",msg);
//             
//             if ([returnData isKindOfClass:[NSDictionary class]])
//             {
//                 _dataDict = [NSDictionary dictionaryWithDictionary:returnData];
//                 
//                 [self getProvince];
//                 [self getProvinceStr];
//             }
//             
//         }else
//         {
//             NSLog(@"msg == %@",msg);
//            
//         }
//     } failure:^(NSError *error)
//     {
//         
//     } showHUD:nil];
}

- (void)getProvince
{
    _provinces = [NSMutableArray array];
    
    int i = 0;
    for (NSArray *arr in self.dataDict[@"0"])
    {
        AddressInfo *info = [[AddressInfo alloc] init];
        info.name = [NSString stringWithFormat:@"%@省",arr.lastObject];
        info.addressId = arr.firstObject;
        
        if (i==0||i==1||i==8||i==21)
        {
            info.name = [NSString stringWithFormat:@"%@市",arr.lastObject];
        }else if (i==4||i==19||i==25||i==29||i==30)
        {
            info.name = [NSString stringWithFormat:@"%@自治区",arr.lastObject];
        }else if (i==32||i==33)
        {
            info.name = [NSString stringWithFormat:@"%@特别行政区",arr.lastObject];
        }else
        {
            info.name = [NSString stringWithFormat:@"%@省",arr.lastObject];
        }

        
        [_provinces addObject:info];
        
        i++;
    }
}

- (NSArray <AddressInfo *>*)getCityWithProvinceId:(NSString *)provinceId
{
    NSMutableArray *arrM = [NSMutableArray array];
    
    for (NSArray *arr in self.dataDict[provinceId])
    {
        AddressInfo *info = [[AddressInfo alloc] init];
        info.name = arr.lastObject;
        info.addressId = arr.firstObject;
        
        [arrM addObject:info];
    }
    
    return [NSArray arrayWithArray:arrM];
}

- (NSArray <AddressInfo *>*)getCountyWithCityId:(NSString *)cityId
{
    NSMutableArray *arrM = [NSMutableArray array];
    
    for (NSArray *arr in self.dataDict[cityId])
    {
        AddressInfo *info = [[AddressInfo alloc] init];
        info.name = arr.lastObject;
        info.addressId = arr.firstObject;
        
        [arrM addObject:info];
    }
    
    return [NSArray arrayWithArray:arrM];
}

- (void)getProvinceStr
{
    _provinceStrs = [NSMutableArray array];
    
    int i = 0;
    for (NSArray *arr in self.dataDict[@"0"])
    {
        if (i==0||i==1||i==8||i==21)
        {
            [_provinceStrs addObject:[NSString stringWithFormat:@"%@市",arr.lastObject]];
        }else if (i==4||i==19||i==25||i==29||i==30)
        {
            [_provinceStrs addObject:[NSString stringWithFormat:@"%@自治区",arr.lastObject]];
        }else if (i==32||i==33)
        {
            [_provinceStrs addObject:[NSString stringWithFormat:@"%@特别行政区",arr.lastObject]];
        }else
        {
            [_provinceStrs addObject:[NSString stringWithFormat:@"%@省",arr.lastObject]];
        }
        
        i++;
    }
}

- (NSArray <NSString *>*)getCityStrWithProvinceId:(NSString *)provinceId
{
    NSMutableArray *arrM = [NSMutableArray array];
    
    for (NSArray *arr in self.dataDict[provinceId])
    {
        [arrM addObject:arr.lastObject];
    }
    
    return [NSArray arrayWithArray:arrM];
}

- (NSArray <NSString *>*)getCountyStrWithCityId:(NSString *)cityId
{
    NSMutableArray *arrM = [NSMutableArray array];
    
    for (NSArray *arr in self.dataDict[cityId])
    {
        [arrM addObject:arr.lastObject];
    }
    
    return [NSArray arrayWithArray:arrM];
}


@end
